﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Estate_Autocomplete2.ascx.cs"
    Inherits="ZLDC.Estate.UserControl.Estate_Autocomplete2" %>

<!-- 带客看盘 -->  
<link href="../js/jquery.autocomplete/jquery.autocomplete.css" rel="stylesheet" type="text/css" />

<script src="../js/jquery/jquery-1.3.2.min.js" type="text/javascript"></script>

<script src="../js/jquery.autocomplete/jquery.autocomplete.min.js" type="text/javascript"></script>

<script src="../js/LexunJS.js" type="text/javascript"></script>

<script type="text/javascript">
    $(function() {
        $('#iEstateName').autocomplete("../Handler/HandlerIndex.ashx?act=estate_auto_list", {
            minChars: 2,
            max: 100,
            //列表里的条目数
            width: 205,
            scroll: true,
            mustMatch: true,
            matchContains: false,
            //提示的宽度，溢出隐藏
            scrollHeight: 300,
            //提示的高度，溢出显示滚动条
            parse: function(data) {
                if (data == "" || data == undefined)
                    return false;

                return $.map(eval(data), function(row) {
                    return {
                        data: row,
                        value: row.id,
                        result: row.name
                    }
                });
            },
            formatItem: function(item) {
                return item.name;
            }
        });
        $("#iEstateName").result(function(event, data, formatted) {
            $("#dname").html("");
            $("#area").html("");
            if (data == null) {
                return;
            }
            var select = document.getElementById("dname");
            LexunJS.selectAddOption(select, data.cityname, data.cityid)
            document.getElementById("dname1").value = data.cityname;
            var sarea = document.getElementById("area");
            document.getElementById("area1").value = data.areaname;
            LexunJS.selectAddOption(sarea, data.areaname, data.areaid)
            document.getElementById("houseType").value = data.type;
            // 选中下拉中某行的事件
            loadBuild(data.id);
        });
    });

    // 清除输入框默认值
    function clearText() {
        document.getElementById("iEstateName").value = "";
    }

    // 设置输入框默认值
    function setText() {
        if (document.getElementById("iEstateName").value == "") {
            document.getElementById("iEstateName").value = "楼盘名称、拼音均可";
        }
    }

    // 级联加载列表
    function loadBuild(id) {
        $.ajax({
            type: 'POST',
            url: '../Handler/HandlerIndex.ashx',
            data: 'act=SelectNamesById&id=' + id,
            timeout: '10000',
            error: function() {
                alert("修改失败！");
            }, success: function(json) {
                loadBuildCallBack(json);
            }
        });
    }

    // 加载城市列表回调
    function loadBuildCallBack(response) {
        var json = eval("(" + response + ")");
        var record = json.record;
        $("#buildName1").html("");
        var obj = document.getElementById("buildName1");
        LexunJS.selectAddOption(obj, "全部", 0);
        if (record == null || record.length == 0)
            return;
        var recordLength = record.length;
        for (var i = 0; i < recordLength; i++) {
            var sName = record[i].name;
            var sValue = record[i].id;
            LexunJS.selectAddOption(obj, sName, sValue);
        }
    }
   
</script>

<input id="iEstateName" name="iEstateName" style="width:28%" type="text" onclick="clearText();" class="textstyle1" onblur="setText();"
    value="楼盘名称、拼音均可" />
